package com.nondo.rdp.finance.domain.circle;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.nondo.rdp.auth.domain.User;
import com.nondo.rdp.core.domain.base.BaseEntity;
import com.nondo.rdp.finance.config.DbConfig;

import javax.persistence.*;

import org.hibernate.validator.constraints.Length;

/**
 * 金融圈-说说-评论
 */
@Entity
@Table(name = DbConfig.DEFAULT_TABLE_PREFIX + "circle_comment")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class CircleComment extends BaseEntity {
    private Long id;        //自增ID
    private Circle circle;  //评论的圈子
    private User user;      //评论用户
    private User toUser;    //回复的谁
    private String body;    //评论内容

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "cid")
    @JsonBackReference
    public Circle getCircle() {
        return circle;
    }

    public void setCircle(Circle circle) {
        this.circle = circle;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "uid")
    @JsonBackReference
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "to_uid")
    @JsonBackReference
    public User getToUser() {
        return toUser;
    }

    public void setToUser(User toUser) {
        this.toUser = toUser;
    }

    @Column(name = "body", length = 600)
    @Length(min = 1, max = 600, message = "评论内容长度不能超过600个字符")
    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }
}
